﻿/**************************************************
*
 * 数据访问层  
 * 评估功能、列表展示、单个数据获取、更新评估数据
 * Author：JXL
 
 *************************************/
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using IDAL;
using Model;
using System.Data;
using System.Data.SqlClient;

namespace DAL
{
    public class AssessDAL : IAssessDAL
    {
        /// <summary>
        /// 评估列表展示
        /// </summary>
        /// <param name="pageindex"></param>
        /// <param name="pagesize"></param>
        /// <param name="wherestr"></param>
        /// <returns></returns>
        public pagelist<Basic_infoss> getlist(int pageindex, int pagesize, string wherestr,int id)
        {
            string tablename = " Basic_Info a,Users b,Department c ";
            string strwhere = " a.the_Department=c.department_Id and a.survey=b.users_Id and a.basic_State>=2 and a.Evaluation="+id+"" + wherestr;
            string strid = "a.basic_UnitPrice,a.projectNumber,b.users_Name,a.survey_StartTime,a.survey_EndTime,c.department_Name,a.basic_CreateTime,a.basic_State";
            string sort = "basic_id";
            using (SqlConnection sql = new SqlConnection(HouseCommon.Common.conn))
            {
                sql.Open();
                SqlCommand cmd = new SqlCommand("Common_PageList", sql);
                cmd.CommandType = CommandType.StoredProcedure;
                SqlParameter[] pa ={
                                     new SqlParameter("@tab",SqlDbType.NVarChar,100),
                                     new SqlParameter("@pageindex",SqlDbType.Int),
                                     new SqlParameter("@pagesize",SqlDbType.Int),
                                     new SqlParameter("@pagecount",SqlDbType.Int),
                                     new SqlParameter("@strFld",SqlDbType.NVarChar,500),
                                     new SqlParameter("@strWhere",SqlDbType.NVarChar,500),
                                     new SqlParameter("@Sort",SqlDbType.NVarChar,50)
                                 };
                pa[0].Value = tablename;
                pa[1].Value = pageindex;
                pa[2].Value = pagesize;
                pa[3].Direction = ParameterDirection.Output;
                pa[4].Value = strid;
                pa[5].Value = strwhere;
                pa[6].Value = sort;
                cmd.Parameters.AddRange(pa);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable ta = new DataTable();
                da.Fill(ta);
                List<Basic_infoss> list = DBhelper.DBHelper.DataTable2List<Basic_infoss>(ta).ToList();

                pagelist<Basic_infoss> liss = new pagelist<Basic_infoss>();
                liss.getlist = list;
                liss.pagecount = (int)pa[3].Value;
                return liss;
            }
        }
        /// <summary>
        /// 获取单个的评估信息
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Basic_infoss getmodel(int id)
        {
            string str = "select basic_Evaluation,basic_UnitPrice,basic_Acreage,basic_Total,basic_ValueTime,survey_StartTime,survey_EndTime from Basic_Info where ProjectNumber=" + id + "";
            using (SqlConnection sql = new SqlConnection(HouseCommon.Common.conn))
            {
                sql.Open();
                SqlCommand cmd = new SqlCommand(str, sql);
                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable ta = new DataTable();
                da.Fill(ta);
                return DBhelper.DBHelper.DataTable2List<Basic_infoss>(ta).FirstOrDefault();
            }
        }
        /// <summary>
        /// 更新单个的评估信息
        /// </summary>
        /// <param name="ba"></param>
        /// <returns></returns>
        public int UpdateBasic(Basic_Info ba)
       {
           string str = "update Basic_Info set basic_Acreage='" + ba.basic_Acreage + "',basic_Total='" + ba.basic_Total + "',basic_ValueTime='" + ba.basic_ValueTime + "',basic_Evaluation='"+ba.basic_Evaluation+"',basic_State=3 where  projectNumber='" + ba.projectNumber + "';";
            using(SqlConnection sql=new SqlConnection (HouseCommon.Common.conn))
            {
                sql.Open();
                SqlCommand cmd = new SqlCommand(str, sql);
                return cmd.ExecuteNonQuery();
            }
       }
    }
}
